package com.itheima.test0910.testThrowException;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入姓名：");
        String nameStr = scanner.nextLine();
        Student student = new Student();
        while(true){
            System.out.println("请输入年龄");
            String ageStr = scanner.nextLine();
            int ageInt = 0;
            try {
                ageInt = Integer.parseInt(ageStr);
            } catch (NumberFormatException e) {
//                e.printStackTrace();
                System.out.println("请输入整数年龄");
                continue;
            }
            boolean success = jugumentAge(ageInt);
            if (success){
                student.setName(nameStr);
                student.setAge(ageInt);
                break;
            }else {
                System.out.println("请输入18-26区间内的年龄");
                continue;
            }
        }
        System.out.println(student.toString());
    }

    private static boolean jugumentAge(int ageInt) {
        if (ageInt >= 18 && ageInt <= 26){
            return true;
        }else {
            return false;
        }
    }
}
